package com.swotxu.screwweb.common.runner;

import com.swotxu.screwweb.config.ScrewConfiguration;
import com.swotxu.screwweb.service.AsyncService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

/**
 * 启动后执行
 * 读取配置后，更新本地文件
 *
 * @Date: 2021/7/16 10:01
 * @Author: xu.hai
 */
@Component
public class SyncDiskFileRunner implements ApplicationRunner {
    private static final Logger log = LoggerFactory.getLogger(SyncDiskFileRunner.class);

    @Autowired
    private ScrewConfiguration configuration;
    @Autowired
    private AsyncService asyncService;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        log.info("服务启动成功，开始更新本地缓存文件");
        configuration.getScrewProperties().getConfigurations().forEach(asyncService::asyncOverrideFile);
    }
}
